package com.jian.java;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;


/**
 * @author Jiange
 * @create 2021-04-04-15:54
 * 为数据库连接建立缓冲池，预先在缓冲池内放入一定数量的连接 当需要建立连接的时候从里面拿出一个 不需要时放回去
 */
public class JDBCPoolTest {
    @Test
    public void test1(){
        try {
            getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void getConnection() throws Exception {
//        DruidDataSource dataSource = new DruidDataSource();
//
//        dataSource.setUsername("");
        InputStream inputStream = new FileInputStream("Durid.properties");
        Properties properties = new Properties();
        properties.load(inputStream);

        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }
}
